//************************************************************************
//Developed by Guo Ming Li 2009/2010
//Source code:
//  The source code may be freely modified or used but this credit section may not be removed 
//  The original author must be notified of any modifications plus a copy of 
//  the changed source code
//Contact info: mailto://gming.li@gmail.com
//************************************************************************
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Globalization;
using System.Reflection;

namespace GML.BizTalk.OperationManager.Library
{
    public enum OperationsType
    {
            MSBTS_AdapterSetting	,
            MSBTS_BTSObject	,
            MSBTS_DeploymentService	,
            MSBTS_GroupSetting	,
            MSBTS_Host	,
            MSBTS_HostInstance	,
            MSBTS_HostInstanceSetting	,
            MSBTS_HostQueue	,
            MSBTS_HostSetting	,
            MSBTS_MessageInstance	,
            MSBTS_MessageInstanceSuspendedEvent	,
            MSBTS_MsgBoxSetting	,
            MSBTS_Orchestration	,
            MSBTS_ReceiveHandler	,
            MSBTS_ReceiveLocation	,
            MSBTS_ReceiveLocationOrchestration	,
            MSBTS_ReceivePort	,
            MSBTS_SendHandler	,
            MSBTS_SendHandler2	,
            MSBTS_SendPort	,
            MSBTS_SendPortGroup	,
            MSBTS_SendPortGroup2SendPort 	,
            MSBTS_Server	,
            MSBTS_ServerHost	,
            MSBTS_ServerSetting	,
            MSBTS_Service	,
            MSBTS_ServiceInstance	,
            MSBTS_ServiceInstanceSuspendedEvent	,
            MSBTS_Setting	,
            MSBTS_TrackedMessageInstance	,
            MSBTS_TrackedMessageInstance2   ,
            RuleSetDeployment   ,
            OrchestrationStateManagement    ,
            OrphanOrchestrationManagement   ,
            BindingInfo,
            ServiceInstances,
            HostInstances,
            SendPorts,
            ReceiveLocations,
            GACVerification
    }

    public enum OrchestrationMethods
    {
        Enlist,
        QueryDependencyInfo,
        QueryInstanceInfo,
        Start,
        Stop,
        Unenlist
    }
    public enum OrchestrationStatus
    {
        Unbound = 1,
        Bound= 2,
        Stopped= 3,
        Started=4
    }

    public class Helper
    {
        public static string ByteArrayToHexString(byte[] bytes)
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                if (bytes != null)
                {
                    foreach (byte num in bytes)
                    {
                        builder.Append(num.ToString("x2", CultureInfo.InvariantCulture));
                    }
                }
                return builder.ToString();

            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                builder = null;
            }
        }

        public static string GetConnectionString(string server, string database)
        {
            //System.Diagnostics.Debug.WriteLine("Building SQL connection string...");
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
            try
            {
                builder.DataSource = server;
                builder.InitialCatalog = database;
                builder.IntegratedSecurity = true;
                builder.ApplicationName = Assembly.GetExecutingAssembly().GetName().Name;
                string str = builder.ToString();
                //System.Diagnostics.Debug.WriteLine("ConnectionString: " + str);
                return str;

            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                builder = null;
            }
        }

        public static string GetDateTimeString(DateTime datetime)
        {
            return datetime.ToString("yyyy-MM-dd_HH_mm_ss");
        }




    }
}
